package com.nineclock.common.exception;

import com.nineclock.common.entity.Result;
import com.nineclock.common.enums.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class BasicExceptionHandler {

    /**
     * 自定义异常处理类
     *
     * @param e
     * @return
     */
    @ExceptionHandler({
            NcException.class
    })
    public Result handlerNcException(NcException e) {
        e.printStackTrace();
        return Result.errorCodeMessage(e.getCode(), e.getMessage());
    }

    @ExceptionHandler({
            Exception.class
    })
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return  Result.errorCodeMessage(
                ResponseEnum.SERVER_ERROR.getCode(),
                ResponseEnum.SERVER_ERROR.getMessage()
        );
    }
}
